[id].vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 页面导航 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 广告1 -->
  7. <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
  8. <!-- 面包屑导航 -->
  9. <div class="breadcrumb">
  10. <div class="inner">
  11. <span class="location">当前位置:</span>
  12. <el-breadcrumb :separator-icon="ArrowRight">
  13. <el-breadcrumb-item>
  14. <NuxtLink to="/">首页</NuxtLink>
  15. </el-breadcrumb-item>
  16. <el-breadcrumb-item>
  17. <NuxtLink :to="`/${parent_pinyin}/index.html`">
  18. {{ routLevelTitle }}
  19. </NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  22. </el-breadcrumb>
  23. </div>
  24. </div>
  25. <!-- 资讯列表 -->
  26. <div class="newsDetail">
  27. <div class="inner">
  28. <div class="innerLeft">
  29. <div class="LeftTop">
  30. <h1>{{ newsDetail.title }}</h1>
  31. <p>
  32. 来源: <span>{{ newsDetail.copyfrom }}</span>
  33. 作者: <span>{{ newsDetail.author }}</span>
  34. 发布时间: <span>{{ time }}</span>
  35. </p>
  36. </div>
  37. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  38. </div>
  39. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  40. <img :src="selectedImage" alt="Preview">
  41. </div>
  42. <!-- 免责声明: -->
  43. <div class="disclaimer" v-if="newsDetail.fromurl">
  44. <p>原文链接:{{ newsDetail.fromurl }}</p>
  45. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  46. </div>
  47. <div v-if="articleChoice">
  48. <!-- 投票 start ---------------------------------------->
  49. <div class="index_3_box_vote" v-if="articleChoice">
  50. <div class="voteTitle">投票区</div>
  51. <div class="inquire">
  52. <p v-if="voteList.length > 0">{{ voteList[0].survey_name }}</p>
  53. <div class="radioBox">
  54. <!--投票选项-->
  55. <div v-if="!isDisabled">
  56. <div class="radio" v-if="isRadio">
  57. <el-radio-group v-model="radio1" @change="handleRadioChange">
  58. <el-radio v-for="item in voteList" :key="item.id" :value="item.id"
  59. size="large">
  60. <span v-if="item.is_other == 0">{{ item.choice_name }}</span>
  61. <span v-else>其他</span>
  62. </el-radio>
  63. </el-radio-group>
  64. <el-input v-if="showUserChoice" v-model="userChoice" :rows="2" type="textarea"
  65. resize="none" placeholder="请输入.." />
  66. </div>
  67. <div class="checkInputBox" v-else>
  68. <el-checkbox-group v-model="check1" @change="handleCheckboxChange">
  69. <span v-for="item in voteList" :key="item.id">
  70. <span v-if="item.is_other == 0">
  71. <el-checkbox size="large" :label="item.choice_name"
  72. :value="item.id" />
  73. </span>
  74. <span v-else>
  75. <el-checkbox size="large" label="其他" :value="item.id" />
  76. </span>
  77. </span>
  78. </el-checkbox-group>
  79. <el-input v-if="showUserChoice" v-model="userChoice" :rows="2" type="textarea"
  80. resize="none" placeholder="请输入.." />
  81. </div>
  82. </div>
  83. <!--投票结果-->
  84. <div class="inquireData" v-else>
  85. <div v-for="item in websiteSurveyData.data" :key="item.id">
  86. <div class="inquireDataItem active" v-if="item.status == 1">
  87. <div class="inquireDataItemTitle">
  88. <span v-if="item.choice_name == ''">其他</span>
  89. <span v-else>{{ item.choice_name }}</span>
  90. </div>
  91. <div class="inquireDataItemNum">{{ item.results }}票</div>
  92. </div>
  93. <div class="inquireDataItem" v-else>
  94. <div class="inquireDataItemTitle">
  95. <span v-if="item.choice_name == ''">其他</span>
  96. <span v-else>{{ item.choice_name }}</span>
  97. </div>
  98. <div class="inquireDataItemNum">{{ item.results }}票</div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <div class="btn">
  104. <button class="voting" @click="addWebsiteSurvey" :disabled="isDisabled"
  105. v-if="!isDisabled">投票</button>
  106. </div>
  107. </div>
  108. </div>
  109. <!-- 投票 end ---------------------------------------->
  110. </div>
  111. </div>
  112. <div class="innerRight">
  113. <!-- 热点资讯1 -->
  114. <div class="hotList1">
  115. <DetailHotNews></DetailHotNews>
  116. </div>
  117. <!-- 热点资讯2 -->
  118. <div class="hotList2">
  119. <DetailHotNews2></DetailHotNews2>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <!-- 页面底部 -->
  125. <HomeFoot1></HomeFoot1>
  126. </template>
  127. <script setup>
  128. //1.页面依赖 start ---------------------------------------->
  129. import { onMounted } from 'vue'
  130. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup ,ElMessage,ElCheckboxGroup,ElCheckbox} from 'element-plus'
  131. import { ArrowRight } from '@element-plus/icons-vue'
  132. //1.1 获得跳转过来的id
  133. const route = useRoute();
  134. //获得详情id
  135. const articleId = parseInt(route.params.id); //获得该页面的id
  136. //获得当前的完整路径
  137. const fullPath = route.path;
  138. //拆分,取出来中间这一段,然后提取数字部分
  139. const segments = fullPath.split('/');
  140. const targetSegment = segments[1];
  141. // const numberPart = targetSegment.match(/\d+$/)?.[0];
  142. // let routeId = 20 //排除路径错误可以打开这个
  143. // const routeId = numberPart;
  144. let routeId;
  145. //通过导航路径反向查询导航id
  146. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  147. method: 'GET',
  148. query: {
  149. 'pinyin': targetSegment,
  150. },
  151. });
  152. if (getRouteId.code == 200) {
  153. routeId = getRouteId.data.category_id
  154. } else {
  155. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  156. console.log("错误位置:通过url路径查询导航池id")
  157. console.log("后端错误反馈:", getRouteId.message)
  158. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  159. }
  160. //1.2 获得父级栏目的名称、id
  161. const parent_name = ref([]);
  162. const parent_id = ref([]);
  163. const parent_pinyin = ref("");
  164. const parent_children_count = ref(0)
  165. let getParentNav = async () => {
  166. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  167. method: 'GET',
  168. query: {
  169. 'catid': routeId
  170. },
  171. });
  172. console.log("获取父级栏目数据")
  173. console.log(listData)
  174. if (listData.code == 200) {
  175. console.log(listData.data);
  176. parent_name.value = listData.data.alias;
  177. parent_id.value = listData.data.parent_id;
  178. parent_pinyin.value = listData.data.aLIas_pinyin;
  179. parent_children_count = listData.data.children_coun;
  180. } else {
  181. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  182. console.log("错误位置:获取面包屑导航")
  183. console.log("后端错误反馈:", listData.message)
  184. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  185. }
  186. }
  187. //获得父级栏目详情
  188. getParentNav();
  189. //1.页面依赖 end ---------------------------------------->
  190. //2.页面数据 start ---------------------------------------->
  191. //2.1 资讯详情
  192. const newsDetail = ref({})
  193. const routeNewsTtitle = ref("");
  194. //2.2 发布日期
  195. const time = ref("");
  196. //2.3 路径
  197. const routLevelTitle = ref("");
  198. const routLevelId = ref("");
  199. //是否展示投票
  200. const articleChoice = ref(false);
  201. //2.4获取详情
  202. async function getPageData() {
  203. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  204. method: 'GET',
  205. query: {
  206. 'articleid': articleId
  207. },
  208. });
  209. if (mkdata.code == 200) {
  210. //判断是否显示投票
  211. if (mkdata.data.is_survey == 1) {
  212. console.log("本篇文章含有投票!")
  213. articleChoice.value = true;
  214. getVoteList();
  215. }
  216. //获取内容
  217. newsDetail.value = mkdata.data;
  218. //获取路径
  219. routLevelTitle.value = newsDetail.value.cat_name;
  220. routLevelId.value = newsDetail.value.category_id;
  221. //获取发布时间
  222. time.value = newsDetail.value.updated_at.split(' ')[0];
  223. //修正标题长度
  224. if (newsDetail.value.title.length >= 30) {
  225. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  226. } else {
  227. routeNewsTtitle.value = newsDetail.value.title
  228. }
  229. } else {
  230. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  231. console.log("错误位置:获取详情内容")
  232. console.log("后端错误反馈:", mkdata.message)
  233. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  234. }
  235. }
  236. getPageData();
  237. //2.5 获得广告
  238. //广告列表
  239. let adImg1 = ref([]);
  240. onMounted(async () => {
  241. const { $webUrl, $CwebUrl } = useNuxtApp();
  242. //广告1
  243. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_detail_0001`
  244. const responseAd1 = await fetch(url, {
  245. headers: {
  246. 'Content-Type': 'application/json',
  247. 'Userurl': $CwebUrl,
  248. 'Origin': $CwebUrl
  249. }
  250. });
  251. const resultAd1 = await responseAd1.json();
  252. adImg1.value = resultAd1.data[0];
  253. })
  254. //2.页面数据 end ---------------------------------------->
  255. //3.设置seo信息 start---------------------------------------->
  256. //3.1 设置seo信息
  257. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  258. method: 'GET',
  259. query: {
  260. 'articleid': articleId
  261. },
  262. });
  263. if (setData.code == 200) {
  264. let seoTitle = setData.data.title;
  265. let seoDescription = setData.data.introduce;
  266. let seoKeywords = setData.data.keyword;
  267. let seoSuffix = setData.data.suffix;
  268. let seoName = setData.data.website_name;
  269. useSeoMeta({
  270. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  271. meta: [
  272. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  273. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  274. ]
  275. });
  276. } else {
  277. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  278. console.log("错误位置:设置详情页面SEO数据")
  279. console.log("后端错误反馈:", setData.message)
  280. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  281. }
  282. //3.设置seo信息 end---------------------------------------->
  283. //4.投票 start---------------------------------------->
  284. const radio1 = ref(''); //单选
  285. const check1 = ref([]); //多选
  286. const isDisabled = ref(false);//是否禁用提交按钮
  287. const isRadio = ref(true);//是否渲染单选
  288. const userSurId = ref('');//投票属于哪一篇文章
  289. const userChoice = ref('');//用于判断用户选择了其他选项以后,输入的值
  290. const userIsChoice = ref('');//用于判断其他选项目前是什么值
  291. const showUserChoice = ref(false);//是否显示其他输入框
  292. const websiteSurveyData = ref([]);//投票结果
  293. //3.2获得投票列表
  294. let voteList = ref([]);
  295. async function getVoteList() {
  296. const voteData = await requestHome('/web/getWebsiteSurvey', { method: 'GET', query: { 'art_id': articleId } });
  297. console.log(778899)
  298. console.log('778899',voteData)
  299. if (voteData.code == 200) {
  300. voteList.value = voteData.data;
  301. console.log(voteList.value)
  302. //判断显示单选还是多选
  303. //survey_type 0是单选 1是多选
  304. if (voteData.data[0].survey_type == 0) {
  305. isRadio.value = true;
  306. console.log("1111")
  307. } else {
  308. isRadio.value = false;
  309. }
  310. //把最后一个的值拿出来 用于判断用户是否选择了其他
  311. for (let item of voteData.data) {
  312. //如果含有其他
  313. if (item.is_other == 1) {
  314. userIsChoice.value = item.id;
  315. }
  316. }
  317. //用户投票属于哪一篇文章
  318. userSurId.value = voteData.data[0].sur_id;
  319. } else {
  320. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  321. console.log("错误位置:首页投票")
  322. console.log("后端错误反馈:", voteData.message)
  323. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  324. }
  325. }
  326. //3.2当用户选择了选项,判断是否展示其他输入框
  327. const handleRadioChange = (value) => {
  328. console.log('11111',value,userIsChoice.value);
  329. if (value == userIsChoice.value) {
  330. showUserChoice.value = true;
  331. } else {
  332. showUserChoice.value = false;
  333. }
  334. }
  335. const handleCheckboxChange = (value) => {
  336. if (value.includes(userIsChoice.value)) {
  337. showUserChoice.value = true;
  338. } else {
  339. showUserChoice.value = false;
  340. }
  341. }
  342. //3.2发起投票
  343. async function addWebsiteSurvey() {
  344. //判断当前是单选还是多选
  345. console.log(isRadio.value)
  346. if (isRadio.value) {
  347. console.log("用户单选!")
  348. if (radio1.value != '') {
  349. //先判断一下是否使用了其他选项
  350. if (showUserChoice.value) {
  351. if (userChoice.value != '') {
  352. //文章id
  353. // console.log(userSurId.value)
  354. // 用户输入的值
  355. // console.log(userChoice.value)
  356. //如果使用了其他,其他的选项需要增加进去
  357. const ChoiceData = await requestHome('/web/addWebsiteSurveyOption', {
  358. method: 'GET',
  359. query: {
  360. 'sur_id': userSurId.value,//投票的新闻id
  361. 'choice_name': userChoice.value,//投票的选项id
  362. }
  363. });
  364. if (ChoiceData.code == 200) {
  365. //提交完其他选项以后,再正式发起投票
  366. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  367. method: 'GET',
  368. query: {
  369. 'sur_id': userSurId.value,
  370. 'choice_id': ChoiceData.data
  371. }
  372. });
  373. if (mkData.code == 200) {
  374. ElMessage.success('投票成功!')
  375. //把投票结果显示到页面上 禁用投票按钮
  376. isDisabled.value = true;
  377. websiteSurveyData.value = mkData.data;
  378. //遍历一下,把用户选中的那个设置status为1
  379. let data = mkData.data;
  380. //遍历一下,把用户选中的那个设置status为1
  381. for (let item of data.data) {
  382. for (let i of data.choice) {
  383. if (item.id == i) {
  384. console.log(item.id)
  385. item.status = 1;
  386. }
  387. }
  388. }
  389. websiteSurveyData.value = data;
  390. } else {
  391. ElMessage.error(mkData.message)
  392. }
  393. } else {
  394. ElMessage.error('其他投票失败!')
  395. }
  396. } else {
  397. ElMessage.error('请输入选项内容!')
  398. }
  399. } else {
  400. console.log('111',userSurId.value);
  401. console.log('222',radio1.value);
  402. //如果没选择其他,直接提交选择的内容
  403. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  404. method: 'GET',
  405. query: {
  406. 'sur_id': userSurId.value,
  407. 'choice_id': radio1.value
  408. }
  409. });
  410. if (mkData.code == 200) {
  411. ElMessage.success('投票成功!')
  412. //把投票结果显示到页面上 禁用投票按钮
  413. isDisabled.value = true;
  414. let data = mkData.data;
  415. //遍历一下,把用户选中的那个设置status为1
  416. for (let item of data.data) {
  417. for (let i of data.choice) {
  418. if (item.id == i) {
  419. item.status = 1;
  420. }
  421. }
  422. }
  423. websiteSurveyData.value = data;
  424. } else {
  425. ElMessage.error('投票失败!')
  426. }
  427. }
  428. } else {
  429. ElMessage.error('请选择一个选项')
  430. }
  431. } else {
  432. console.log("多选!")
  433. //多选
  434. if (check1.value != []) {
  435. //先判断一下是否使用了其他选项
  436. if (showUserChoice.value) {
  437. if (userChoice.value != '') {
  438. //判断用户是否只选择了一个其他
  439. if (check1.value.length == 1) {
  440. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  441. method: 'GET',
  442. query: {
  443. 'sur_id': userSurId.value,//投票的新闻id
  444. 'choice_name': userChoice.value,//用户输入的其他选项文字
  445. }
  446. });
  447. if (ChoiceData.code == 200) {
  448. //提交完其他选项以后,再正式发起投票
  449. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  450. method: 'GET',
  451. query: {
  452. 'sur_id': userSurId.value,
  453. 'choice_id': ChoiceData.data
  454. }
  455. });
  456. if (mkData.code == 200) {
  457. ElMessage.success('投票成功!')
  458. //把投票结果显示到页面上 禁用投票按钮
  459. isDisabled.value = true;
  460. websiteSurveyData.value = mkData.data;
  461. //遍历一下,把用户选中的那个设置status为1
  462. let data = mkData.data;
  463. //遍历一下,把用户选中的那个设置status为1
  464. for (let item of data.data) {
  465. for (let i of data.choice) {
  466. if (item.id == i) {
  467. console.log(item.id)
  468. item.status = 1;
  469. }
  470. }
  471. }
  472. websiteSurveyData.value = data;
  473. } else {
  474. ElMessage.error(mkData.message)
  475. }
  476. } else {
  477. ElMessage.error('其他投票失败!')
  478. }
  479. } else {
  480. //用户选择了除了其他以外,还包括别的选项
  481. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  482. method: 'GET',
  483. query: {
  484. 'sur_id': userSurId.value,//投票的新闻id
  485. 'choice_name': userChoice.value,//用户输入的其他选项文字
  486. }
  487. });
  488. if (ChoiceData.code == 200) {
  489. let data = check1.value;
  490. //找到多选的数组,把其他默认值给替换掉
  491. for (let i = 0; i < data.length; i++) {
  492. if (data[i] == userIsChoice.value) {
  493. data[i] = ChoiceData.data;
  494. }
  495. }
  496. let jsonArray = JSON.stringify(data);
  497. //提交完其他选项以后,再正式发起投票
  498. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  499. method: 'GET',
  500. query: {
  501. 'sur_id': userSurId.value,
  502. 'choice_id': jsonArray
  503. }
  504. });
  505. if (mkData.code == 200) {
  506. ElMessage.success('投票成功!')
  507. //把投票结果显示到页面上 禁用投票按钮
  508. isDisabled.value = true;
  509. websiteSurveyData.value = mkData.data;
  510. //遍历一下,把用户选中的那个设置status为1
  511. let data = mkData.data;
  512. //遍历一下,把用户选中的那个设置status为1
  513. for (let item of data.data) {
  514. for (let i of data.choice) {
  515. if (item.id == i) {
  516. //console.log(item.id)
  517. item.status = 1;
  518. }
  519. }
  520. }
  521. websiteSurveyData.value = data;
  522. } else {
  523. ElMessage.error(mkData.message)
  524. }
  525. } else {
  526. ElMessage.error('其他投票失败!')
  527. }
  528. }
  529. } else {
  530. ElMessage.error('请输入选项内容!')
  531. }
  532. } else {
  533. let jsonArray = JSON.stringify(check1.value);
  534. //如果没选择其他,直接提交选择的内容
  535. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  536. method: 'GET',
  537. query: {
  538. 'sur_id': userSurId.value,
  539. 'choice_id': jsonArray
  540. }
  541. });
  542. if (mkData.code == 200) {
  543. ElMessage.success('投票成功!')
  544. //把投票结果显示到页面上 禁用投票按钮
  545. isDisabled.value = true;
  546. websiteSurveyData.value = mkData.data;
  547. //遍历一下,把用户选中的那个设置status为1
  548. let data = mkData.data;
  549. //遍历一下,把用户选中的那个设置status为1
  550. for (let item of data.data) {
  551. for (let i of data.choice) {
  552. if (item.id == i) {
  553. console.log(item.id)
  554. item.status = 1;
  555. }
  556. }
  557. }
  558. websiteSurveyData.value = data;
  559. } else {
  560. ElMessage.error('投票失败!')
  561. }
  562. }
  563. } else {
  564. ElMessage.error('请选择一个选项')
  565. }
  566. }
  567. }
  568. //4.投票 end---------------------------------------->
  569. //5.页面图片放大 start---------------------------------------->
  570. const previewVisible = ref(false)
  571. const selectedImage = ref(' ')
  572. const openPreview = (event) => {
  573. if (event.target.tagName === 'IMG') {
  574. selectedImage.value = event.target.src;
  575. previewVisible.value = true;
  576. }
  577. }
  578. const closePreview = () => {
  579. previewVisible.value = false;
  580. }
  581. //5.页面图片放大 end---------------------------------------->
  582. </script>
  583. <style lang="less" scoped>
  584. @import url('@/assets/css/detail.less');
  585. </style>